#include "Tank.h" 
#include "CsvUtil.h"

Tank::Tank(){
	m_head = NULL;
	m_body = NULL;
}

Tank::~Tank(){

}


Tank* Tank::createWithNum(int num){
	auto tank = new Tank();
	if (tank && tank->initWithNum(num)){
		tank->autorelease();
	}
	else{
		CC_SAFE_DELETE(tank);
		tank = NULL;
	}
	return tank;
}

bool Tank::initWithNum(int num){
	m_head = Sprite::create(StringUtils::format("tank/head%d.png", num).c_str());
	m_body = Sprite::create(StringUtils::format("tank/body%d.png", num).c_str());
	auto anchor = CsvUtil::getInstance()->getFloat(num, 1, "tank/tank.csv");
	auto offset = CsvUtil::getInstance()->getFloat(num, 2, "tank/tank.csv");
	auto scale = CsvUtil::getInstance()->getFloat(num, 3, "tank/tank.csv");
	this->setContentSize(m_body->getContentSize()*0.4);
	this->addChild(m_head, 2);
	this->addChild(m_body, 1);
	this->setScale(scale);
	m_head->setPosition(m_head->getPosition()+Vec2(0,offset));
	m_head->setAnchorPoint(Vec2(0.5, anchor));
	return true;
}


void Tank::onEnter(){
	
}

float Tank::getHeadRotation(){
	return m_headRotation;
}

void Tank::setHeadRotation(float rotation){
	m_head->setRotation(rotation);
	m_headRotation = rotation;
}
